package com.lagou.advice;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/*  通知类*/
@Component
@Aspect // 升级为切面类：配置切入点和通知的关系
public class MyAdvice {
    @Pointcut("execution(* com.lagou.service.impl.AccountServiceImpl.*(..))")
    public void myPointCut(){}

    /*@Before("MyAdvice.myPointCut()")
    public void before(){
        System.out.println("前置方法执行了...");
    }

    @AfterReturning("MyAdvice.myPointCut()")
    public void afterReturning(){
        System.out.println("后置方法执行了...");
    }

    @AfterThrowing("MyAdvice.myPointCut()")
    public void afterThrowing(){
        System.out.println("异常方法执行了...");
    }

    @After("MyAdvice.myPointCut()")
    public void after(){
        System.out.println("最终方法执行了...");
    }*/

    @Around("MyAdvice.myPointCut()")
    public Object arround(ProceedingJoinPoint pjp){
        Object proceed = null;
        try {
            System.out.println("前置方法执行了...");
            proceed = pjp.proceed();
            System.out.println("后置方法执行了...");
        } catch (Throwable throwable) {
            throwable.printStackTrace();
            System.out.println("异常方法执行了...");
        } finally {
            System.out.println("最终方法执行了...");
        }
        return proceed;
    }
}
